﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace TheCup.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.blogs = new ApiControllers.BlogController().Get().Take(8);
            ViewBag.comments = new CommentController().Get(null, 13);

            // we want all active events, so get all events and filter all expired events that was deleted earlier than 5 days ago
            // we may have to create a specific API for this later on if too many events are in the database
            List<Event> ev = new ApiControllers.EventController().Get().OrderBy(x => x.IsExpired).ThenBy(dt => dt.StartDate).ToList<Event>();
            ev.RemoveAll(ee => ee.IsExpired && (ee.DateDeleted < DateTime.Now.AddDays(-5)));
            ViewBag.events = ev;
            //ViewBag.rounds = new ApiControllers.RoundController().Get().Where(x => x.IsPrivate ==false).Take(8);
            ViewBag.rounds = new ApiControllers.RoundController().Get().Take(8);
            
            return View();
        }

        [Authorize(Roles="User")]
        public ActionResult Chat()
        {
            return View();
        }

        public ActionResult About()
        {
            return View();
        }

    }
}
